﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ArrayType : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        #region 一维数组
        int[] arr1 = new int[10];
        int[] arr2 = new int[] {1,2,3,4,5,6,7,8,9,10};
        for (int i = 0;i<arr1.Length;i++) {
            arr1[i] = (i + 1) * 10;
            Response.Write(arr1[i] + "&nbsp;");
        }
        Response.Write("<br>");

        foreach (var x in arr2) {
            Response.Write(x + "&nbsp;");
        }
        Response.Write("<br>");
        #endregion

        #region  多维数组
        int[,] arr3 = new int[3,4]; //二维数组
        Response.Write(arr3.Length + "<br>");
        int[,,] arr4 = new int[3,4,5];  //三维数组
        Response.Write(arr4.Length + "<br>");
        for (int i=0;i<arr3.GetLength(0);i++) {
            for (int j=0;j<arr3.GetLength(1);j++) {
                arr3[i, j] = (i + 1) * (j + 1);
                Response.Write(arr3[i,j] + "&nbsp;");
            }
        }
        Response.Write("<br>");
        #endregion

        #region  数组的数组
        int[][] arr5 = new int[3][];    //具有三个数组元素的数组
        //for (int i = 0;i<arr5.Length;i++) {
        //    arr5[i] = new int[4];
        //}
        arr5[0] = new int[2] {1,2};
        arr5[1] = new int[3] {3,4,5};
        arr5[2] = new int[4] {6,7,8,9};
        foreach (int[] arr in arr5) {
            foreach (int x in arr) {
                Response.Write(x + "&nbsp;");
            }
        }
        Response.Write("<br>");
        #endregion
    }
}